<?php
$connection = mysqli_connect('localhost', 'root', '123456', 'PhanTrangPHPMySql') or die('Could not connect to DB');
//xac dinh bao nhieu dong
$display = $_GET['display'];
$page = $_GET['page'];
$start = $_GET['start'];

$sql = "SELECT email,
                CONCAT_WS(' ',first_name,last_name) AS name
                FROM User
                ORDER BY id
                LIMIT $start, $display";
$result = mysqli_query($connection, $sql) or die('Could not select email' . mysqli_error($connection));
$resultArr = array();
$i = 1;
while ($set = mysqli_fetch_array($result, MYSQL_ASSOC)) {
    $name = $set['name'];
    $email = $set['email'];
    $resultArr[$i] = "<tr><td>$email</td><td>$name</td></tr>";
    $i++;
}
echo json_encode($resultArr);

//if ($page > 1) {
//    $next = $start + $display;
//    $prev = $start - $display;
//    $current = ($start / $display) + 1;
//
////            if ($current != 1) {
////                echo "<li><a href='index.php?start=$prev&page=$page'>Previous</a></li>";
////            }
//    if ($current != 1) {
//        echo "<li><a href='changePage($prev,$page);'>Previous</a></li>";
//    }
//
//    for ($i = 1; $i <= $page; $i++) {
//        if ($current != $i) {
//            //echo "<li><a href='index.php?start=" . $display * ($i - 1) . "&page=$page'>$i</a></li>";
//            echo "<li><a href='changePage(".$display * ($i - 1).",$page);'>$i</a></li>";
//        } else {
//            echo "<li class='current'>$i</li>";
//        }
//    }
////            if ($current != $page) {
////                echo "<li><a href='index.php?start=$next&page=$page'>Next</a></li>";
////            }
//
//    if ($current != 1) {
//        echo "<li><a href='changePage($next,$page);'>Next</a></li>";
//    }
//}
?>

